﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using GolSig.Library;

namespace GolSig.Webforms
{
    public partial class MainForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod]
        public static IEnumerable<CellInfo> Initialize()
        {
           var game = new Game(new BoardSize(50,50));
           game.Initialize(GetLifeOnes(1000));
           return game.Cells();
        }

        [WebMethod]
        public static IEnumerable<CellInfo> Step(CellInfo[] cells)
        {
            var game = new Game(new BoardSize(50, 50));
            game.Initialize(cells);
            game.Next();
            return game.Cells();
        }

        private static CellInfo[] GetLifeOnes(int max)
        {
            var lifeOnes = new List<CellInfo>();
            Random r = new Random();

            for (int i = 0; i < max; i++)
            {
                lifeOnes.Add(new CellInfo(new Position(r.Next(50), r.Next(50)), true));
            }
            return lifeOnes.ToArray();
        }

    }
}